local longyi = fk.CreateSkill{
  name = "mini__longyis",
  tags = { Skill.Force },
}

local miniUtil = require "packages/mini/mini_util"

Fk:loadTranslationTable{
  ["mini__longyis"] = "龙翊",
  [":mini__longyis"] = "<a href='MiniForceSkill'>奋武技</a>，当你使用或打出牌时，你可以亮出牌堆顶至多X张牌，若这些牌花色"..
    "均与你使用或打出的牌不同，你令一名角色获得这些牌（X为存活角色数的一半，向上取整）。",

  ["#mini__longyis-give"] = "龙翊：将这些牌交给一名角色",

  ["$mini__longyis1"] = "愿从皇叔，共匡汉室！",
  ["$mini__longyis2"] = "云与皇叔意气相投，誓要随扈左右。",
}

---@type TrigSkelSpec<UseCardFunc|RespondCardFunc>
local longyiSpec = {
  anim_type = "support",
  max_round_use_time = function(self, player)
    return 1 + player:getMark("mini__longyis_force_times-round")
  end,
  times = function(self, player)
    return 1 + player:getMark("mini__longyis_force_times-round") - player:usedSkillTimes(longyi.name, Player.HistoryRound)
  end,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(longyi.name) and player:usedSkillTimes(longyi.name, Player.HistoryRound) < 1 + player:getMark("mini__longyis_force_times-round")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards((#room.alive_players + 1) // 2)
    room:turnOverCardsFromDrawPile(player, cards, longyi.name)
    local card = data.card
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if table.every(cards, function(id) return card:compareSuitWith(Fk:getCardById(id), true) end) then
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = room.alive_players,
        prompt = "#mini__longyis-give",
        skill_name = longyi.name,
        cancelable = false,
      })[1]
      room:obtainCard(to, cards, false, fk.ReasonGive, player, longyi.name)
    end
    room:cleanProcessingArea(cards, longyi.name)
  end
}

longyi:addEffect(fk.CardUsing, longyiSpec)

longyi:addEffect(fk.CardResponding, longyiSpec)

miniUtil.addForceSkillEffect(longyi)

return longyi
